package com.itheima.controller;

import com.itheima.domain.Book;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

public class BookController {
    //使用原生request对象传递参数
    @RequestMapping("/showPageAndData1")
    public String showPageAndData1(HttpServletRequest request){
        request.setAttribute("name","itheima");
        return "page";
    }

    //使用Model形参传递参数
    @RequestMapping("/showPageAndData2")
    public String showPageAndData2(Model model){
        //添加书籍的方式,key对value
        model.addAttribute("name","Jock");
        Book book = new Book();
        book.setName("Spring入门案例");
        book.setPrice(66.66d);
        //添加数据的方式,key对value
        model.addAttribute("book",book);
        return "page";
    }
}
